package cn.fl.quato.service.impl;

import java.util.List;

import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.project.dto.PrjBscInfoDTO;
import cn.fl.quato.dto.QuatoBscInfoDTO;
import cn.fl.quato.dto.QuatoChangeHistoryDTO;
import cn.fl.quato.dto.QuatoPrjTypChangeHistoryDTO;
import cn.fl.quato.service.IQuatoApiService;
import cn.fl.quato.service.IQuatoBscInfoService;
import cn.fl.quato.transform.QuatoBscInfoVOTransform;
import cn.fl.quato.transform.QuatoChangeHistoryVOTransform;
import cn.fl.quato.transform.QuatoPrjTypChangeHistoryVOTransform;
import cn.fl.quato.vo.QuatoBscInfoVO;
import cn.fl.quato.vo.QuatoChangeHistoryVO;
import cn.fl.quato.vo.QuatoPrjTypChangeHistoryVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cmm.mid.core.framework.page.Pager;


/**
 * @Description: 资管额度管理基础表 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class QuatoBscInfoServiceImpl implements IQuatoBscInfoService {

	/**
	 * 日志
	 */
	private static final Logger logger = LoggerFactory.getLogger(QuatoBscInfoServiceImpl.class);
	
	/**
	 * 自定义 API 自行注入需要的API服务
	 */
	@Autowired
	private IQuatoApiService quatoApiService;

	@Override
	public QuatoBscInfoVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "selectById", "主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "获取对象主键不能为空!");
		}
		//QuatoBscInfoDTO dto = this.quatoBscInfoApiService.selectById(id);
		return null;
	}

	@Override
	public QuatoBscInfoVO selectQuatoBscInfoById(Long id, String sysCd) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "selectQuatoBscInfoDTOById", "主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "获取对象主键不能为空!");
		}
		QuatoBscInfoDTO dto = quatoApiService.selectQuatoBscInfoById(id,sysCd);
		return QuatoBscInfoVOTransform.toVO(dto);
	}

	@Override
	public List<QuatoBscInfoVO> isExistSameInfo(Long id,String insCode, String buOrgCd, String prjTypCd) throws BaseException {
		List<QuatoBscInfoDTO> quatoBscInfoVOList = quatoApiService.isExistSameInfo(id,insCode,buOrgCd,prjTypCd);
		return QuatoBscInfoVOTransform.toVOList(quatoBscInfoVOList);
	}

	@Override
	public Long add(QuatoBscInfoVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "add", "新增对象不存在!");
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"新增对象不存在!");
		};
		return this.quatoApiService.add(QuatoBscInfoVOTransform.toDTO(entity));
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "removeById", "删除对象主键不能为空!");
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"删除对象主键不能为空!");
		};
		//return this.quatoBscInfoApiService.removeQuatoBscInfoDTOById(id);
		//TODO 业务逻辑
		return false;
	}
	
	/**
     * 删除
     * @param ids
     * @return
     */
    public boolean removeByIds(List<Long> ids)throws BaseException{
		if(CollectionUtils.isEmpty(ids)){
			BaseLogUtils.info(logger, "removeByIds", "删除主键参数集合不能为空!", CurrentThreadContext.getCurrentUserName());
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"删除对象主键不能为空!");
		};
		return false;
    }

	@Override
	public boolean modify(QuatoBscInfoVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "modify", "修改对象不能为空!");
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"修改对象不能为空!");
		};
		//return this.quatoBscInfoApiService.modifyQuatoBscInfoDTO(QuatoBscInfoVOTransform.toDTO(entity));
		//TODO 业务逻辑
		return false;
	}

	@Override
	public Pager searchListPage(Pager page, String sysCd) throws BaseException{
		if(null == page){
			page = new Pager();
		}
		page = this.quatoApiService.searchQuatoBscInfoListPage(page,sysCd);
		page.setResultList(QuatoBscInfoVOTransform.toVOList((List<QuatoBscInfoDTO>)page.getResultList()));
		return page;
	}

	@Override
	public boolean modifyQuato(QuatoChangeHistoryVO entity) throws BaseException {
		return this.quatoApiService.modifyQuato(QuatoChangeHistoryVOTransform.toDTO(entity));
	}

	@Override
	public List<QuatoChangeHistoryVO> getQuatoChangeHistory(Long quatoId) throws BaseException {
		List<QuatoChangeHistoryDTO> quatoChangeHistoryDTO = this.quatoApiService.getQuatoChangeHistory(quatoId);
		return QuatoChangeHistoryVOTransform.toVOList(quatoChangeHistoryDTO);
    }

	@Override
	public List<QuatoPrjTypChangeHistoryVO> getQuatoPrjTypCdChangeHistory(Long quatoId) throws BaseException {
		List<QuatoPrjTypChangeHistoryDTO> quatoPrjTypChangeHistoryDTOS = this.quatoApiService.getQuatoPrjTypCdChangeHistory(quatoId);
		return QuatoPrjTypChangeHistoryVOTransform.toVOList(quatoPrjTypChangeHistoryDTOS);
	}

	@Override
	public boolean modifyPrjTypCd(QuatoPrjTypChangeHistoryVO entity) throws BaseException {
		return quatoApiService.modifyPrjTypCd(QuatoPrjTypChangeHistoryVOTransform.toDTO(entity));
	}
}
